// OPCDevice.h : Declaration of the COPCDevice
#ifndef OPCDEVICE_H
#define OPCDEVICE_H

#pragma once
#include "resource.h"       // main symbols
#include "OPCDA.h"

#include <mysql.h>
#include <string>
#include <vector>

// Item data types
#define UNKNOWN -1
#define INTEGER 0
#define FLOAT 1

// Quality
#define UNCERTAIN -1
#define BAD 0
#define GOOD 1

using namespace std;

class COPCDevice
{
public:

    // Gets an instance of the class
    static COPCDevice & instance ()
    {
        if (!device)
            device = new COPCDevice;
        return *device;
    }

	// Destructor
    ~COPCDevice ();

	HRESULT CheckOperation(void);
	HRESULT Read(LPWSTR szItemID, VARIANT* pvValue, WORD* pwQuality);
	HRESULT Write(LPWSTR szItemID, VARIANT vValue);
	HRESULT GetAccessRights(LPWSTR szItemID, DWORD* pdwAccessRights);
	HRESULT GetDeviceHandle(LPWSTR szItemID, INT_PTR* phDevice);
	HRESULT WriteLock(INT_PTR hDevice);
	HRESULT WriteUnlock(INT_PTR hDevice);
	HRESULT ReadLock(INT_PTR hDevice);
	HRESULT ReadUnlock(INT_PTR hDevice);
	vector<string> SearchItems(char * name);
	vector<string> AllItems();

private:
    // Constructor 
    COPCDevice ();

    // Pointer to the singleton
    static COPCDevice *device;

	// Pointer to database
	MYSQL* m_pLinkDb;

};

#endif OPCDEVICE_H